package com.firebird.app.reader.pdf.adapter

import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

import com.firebird.app.reader.R
import com.firebird.app.reader.pdf.bean.FileListBean

class ChooseFileAdapter(fileListBeans: List<FileListBean>?) : RecyclerView.Adapter<ChooseFileAdapter.ViewHolder>() {
    private var fileListBeans: List<FileListBean>? =null

    override fun onCreateViewHolder(viewGroup: ViewGroup, i: Int): ViewHolder {
        val view = View.inflate(viewGroup.context, R.layout.item_file_list, null)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(vH: ViewHolder, i: Int) {
        vH.fileNameTv?.setText(fileListBeans!![i].fileName)
        vH.updateTimeTv?.setText(fileListBeans!![i].updateTime)
        vH.itemView.setOnClickListener(View.OnClickListener { v -> mOnItemClickListener?.onItemClick(v, i) })
    }

    override fun getItemCount(): Int {
        return fileListBeans?.size ?: 0
    }

    inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var fileNameTv:TextView?=null
        var updateTimeTv: TextView?=null

        init {
            fileNameTv = itemView.findViewById<View>(R.id.ifl_file_name_tv) as TextView
            updateTimeTv = itemView.findViewById<View>(R.id.ifl_file_update_time_tv) as TextView
        }
    }

    interface OnItemClickListener {
        fun onItemClick(view: View?, position: Int)
    }

    private var mOnItemClickListener: OnItemClickListener? = null

    fun setOnItemClickListener(mOnItemClickListener: OnItemClickListener?) {
        this.mOnItemClickListener = mOnItemClickListener
    }

    init {
        this.fileListBeans = fileListBeans!!
    }
}

